<template>
  <mars-dialog customClass="base-pannel" right="0" top="0" width="100%" height="60px" padding="0,10" border-radius="0px">
    <div class="mars3d-wrapper">
      <!-- 标题容器 -->
      <div class="header-title" style="background-image: url('/img/header-CE2FZDIm.png')">
        <h1 class="title-text">农业应急服务管理平台</h1>
      </div>

      <!-- 图例容器 -->
      <div class="legend-container">
        <div class="legend-items">
          <!-- 平急两用 -->
          <div class="legend-item" @click="filterMarkers('lyfwzx')">
            <div class="legend-icon">
              <img src="https://data.mars3d.cn/img/marker/mark-red.png" alt="平急两用" class="icon-image" />
            </div>
            <span class="legend-desc">平急两用</span>
          </div>
          <!-- 农机应急服务队 -->
          <div class="legend-item" @click="filterMarkers('njyjfwd')">
            <div class="legend-icon">
              <img src="https://data.mars3d.cn/img/marker/point-yellow.png" alt="农机应急" class="icon-image" />
            </div>
            <span class="legend-desc">服务队</span>
          </div>
          <!-- 农机合作 -->
          <div class="legend-item" @click="filterMarkers('other')">
            <div class="legend-icon">
              <img src="https://data.mars3d.cn/img/marker/lace-red.png" alt="农机合作" class="icon-image" />
            </div>
            <span class="legend-desc">服务组织</span>
          </div>
          <!-- 区域站 -->
          <div class="legend-item" @click="filterMarkers('quyuzhan')">
            <div class="legend-icon">
              <img src="https://data.mars3d.cn/img/marker/mark-blue.png" alt="区域站图标" class="icon-image" />
            </div>
            <span class="legend-desc">区域站</span>
          </div>

          <!-- 全部显示 -->
          <div class="legend-item" @click="showAllMarkers" style="margin-left: 15px; border-left: 1px solid #fff; padding-left: 15px">
            <div class="legend-icon" style="width: 18px; height: 18px;">
              <i class="el-icon-refresh"></i>
            </div>
            <span class="legend-desc">全部</span>
          </div>
        </div>
      </div>
    </div>
  </mars-dialog>
</template>

<script setup lang="ts">
import { ref } from "vue"
import { useWidget } from "@mars/common/store/widget"
import * as mapWork from "./map"
import useLifecycle from "@mars/common/uses/use-lifecycle"

const { activate } = useWidget()
useLifecycle(mapWork)

// 图例点击事件处理
const filterMarkers = (type: string) => {
  console.log(`筛选标记类型: ${type}`)

  // 修复：在switch关键字后添加空格
  switch (type) {
    case "quyuzhan":
      mapWork.showOnlyQuyuzhanStations()
      break
    case "lyfwzx":
      mapWork.showOnlyYingjifuwuLyfwzx()
      break
    case "njyjfwd":
      mapWork.showOnlyYingjifuwuNjyjfwd()
      break
    case "other":
      mapWork.showOnlyYingjifuwuOther()
      break
  }
}

// 显示所有标记
const showAllMarkers = () => {
  mapWork.clearAllMarkers()
  mapWork.showAllMarkers()
}
</script>

<style lang="less">
.mars3d-wrapper {
  position: relative;
  height: 7vh;
  width: 100%;
}

.header-title {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 80px;
  display: flex;
  justify-content: center;
  align-items: center;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  z-index: 1000;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.title-text {
  color: #fff;
  font-size: 28px;
  font-weight: bold;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
  margin: 0;
  padding: 0 20px;
  background-color: transparent;
  border-radius: 5px;
}

.mars-dialog .mars-dialog__content[data-v-f8c44a9f] {
  height: 100%;
  padding: 14px;
  overflow: auto;
  border-radius: 4px;
  background-color: rgb(40 62 64);
}

.legend-container {
  position: absolute;
  top: 38%;
  right: 15px;
  padding: 5px 10px;
  background-color: rgba(40, 62, 64, 0.8);
  border-radius: 4px;
  z-index: 1001;
}

.legend-items {
  display: flex;
  align-items: center;
  gap: 15px;
}

.legend-item {
  display: flex;
  align-items: center;
  color: #fff;
  cursor: pointer;
  transition: all 0.2s;

  &:hover {
    transform: scale(1.05);
    text-shadow: 0 0 5px rgba(255, 255, 255, 0.7);
  }
}

.legend-icon {
  width: 24px;
  height: 24px;
  margin-right: 5px;
}

.icon-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.legend-desc {
  font-size: 12px;
  white-space: nowrap;
}
</style>
